package com.endurance.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/ribbon02")
public class Ribbon2Controller {

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @GetMapping
    public HashMap ribbonLoadBalance() {
        ServiceInstance ser = loadBalancerClient.choose("PRODUCT");
        HashMap forObject = new RestTemplate().getForObject(ser.getUri() + "/product/findAll", HashMap.class);
        System.out.println(forObject);
        return forObject;
     }



 }
